package cn.cloudplug.instar.module.map.service;

import android.util.Log;

import cn.cloudplug.instar.http.BaseResponse;
import cn.cloudplug.instar.http.ObjectLoader;
import cn.cloudplug.instar.http.RetrofitServiceManager;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
import rx.Observable;
import rx.functions.Func1;

/**
 * Created by Administrator on 2018-01-16.
 */

public class LocationLoader extends ObjectLoader {
    private LocationService mLocationService;

    public LocationLoader() {
        mLocationService = RetrofitServiceManager.getInstance().create(LocationService.class);
    }

    public Observable<String> submitRealtimeData(long deviceId, Double longitude, Double latitude) {
        return observe(mLocationService.submitRealtimeData(deviceId, longitude, latitude))
                .map(new Func1<BaseResponse<String>, String>() {
                    @Override
                    public String call(BaseResponse<String> stringBaseResponse) {
                        //可以处理对应的逻辑后在返回


                        return stringBaseResponse.data;
                    }
                });
    }

    public interface LocationService {
        @FormUrlEncoded
        @POST("/api/Device/SubmitLocationLngLat")
        Observable<BaseResponse<String>> submitRealtimeData(@Field("deviceId") long deviceId, @Field("longitude") Double longitude, @Field("latitude") Double latitude);
    }

}
